package com.gitee.openviducn.inspector.common;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * 异常内容管理
 * @Author: https://gitee.com/wesleyOne
 * @Date: 12.07 2019
 */
public enum ResponseError {

    /**
     *
     */
    AUTH_CA_ERROR("1000000","帐号认证异常"),
    AUTH_ERROR("1000001","帐号异常"),
    SYSTEM_BUSY("9999999","系统繁忙"),
    SYSTEM_ERR("9999998","系统异常"),
    PARAM_ERR("9999997","参数异常"),

    OPENVIDU_CLIENT_ERR("2000000", "OPENVIDU客户端异常"),
    OPENVIDU_HTTP_ERR("2000001", "OPENVIDU请求异常"),
    CDE_TYPE_NULL("2000100","CDR类型不支持"),
    CDR_PROCESS_NULL("2000101","CDR处理器不存在"),
    ;

    private String code;
    private String msg;
    ResponseError(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private static final Map<String, ResponseError> ENUMS = new HashMap<>();
    static {
        for (ResponseError s : EnumSet.allOf(ResponseError.class)) {
            ENUMS.put(s.getMsg(), s);
        }
    }

    public String getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    /**
     * 根据值获取相应的枚举类型
     * @param code  编码
     * @return      枚举
     */
    public static ResponseError fromValue(String code) {
        return ENUMS.get(code);
    }
}
